<template>
  <div class="sector">
    <el-table :data="carData.data" style="width: 100%">
      <el-table-column prop="createTime" label="日期" width="180" fixed="left">
      </el-table-column>

      <el-table-column label="车型" width="250">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>车型: {{ scope.row.motorcycleType }}</p>
            <p>地址: {{ scope.row.address }}</p>
            <p>座位: {{ scope.row.seat }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.model }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>

      <el-table-column prop="userID.account" label="所属人" width="120">
      </el-table-column>

      <el-table-column label="图片" width="120">
        <template slot-scope="scope">
          <img
            width="50"
            v-if="scope.row.imgs[0]"
            style="border-radius: 2px"
            :src="'http://192.168.7.61:4800/images/' + scope.row.imgs[0]"
            alt
          />
          <img
            width="50"
            v-else
            style="border-radius: 2px"
            src="http://192.168.7.61:4800/images/default2.jpg"
            alt
          />
        </template>
      </el-table-column>

      <el-table-column prop="rent" label="租金(天)" width="120">
      </el-table-column>

      <el-table-column prop="licensePlate" label="车牌" width="120">
      </el-table-column>

      <el-table-column prop="value" label="评分" width="120"> </el-table-column>

      <el-table-column label="审核状态" width="120">
        <template slot-scope="scope">
          <el-tooltip
            class="item"
            effect="dark"
            content="点击修改状态"
            placement="top"
          >
            <el-button
              type="primary"
              size="mini"
              @click="changeVerify(scope.row._id, scope.row.verify)"
              >{{ scope.row.verify }}</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>

      <el-table-column label="出租状态" width="120">
        <template slot-scope="scope">
          <el-tooltip
            class="item"
            effect="dark"
            content="点击修改状态"
            placement="top"
          >
            <el-button
              type="primary"
              size="mini"
              @click="changeStatus(scope.row._id, scope.row.status)"
              >{{ scope.row.status }}</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>

      <el-table-column fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="GpToUpDataCat(scope.row._id)"
            >编辑</el-button
          >
          <el-button size="mini" type="danger" @click="dele(scope.row._id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="carData.currentPage - 0"
      :page-sizes="[5, 8, 10, 15]"
      :page-size="8"
      layout="total, sizes, prev, pager, next, jumper"
      :total="carData.total - 0"
    >
    </el-pagination>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions, mapState, mapMutations } = createNamespacedHelpers("car");

export default {
  data() {
    return {
      userList: [],
    };
  },
  created() {
    this.findAllCar();
  },
  methods: {
    ...mapActions([
      "findAllCar",
      "delCar",
      "clickChangeVerify",
      "clickChangeStatus",
    ]),
    ...mapMutations(["setCurrent", "setPageSize"]),

    dele(_id) {
      // 删除提示框
      this.$confirm("此操作将永久删除该客户, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "danger",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.delCar(_id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    changeStatus(_id, type) {
      this.clickChangeStatus({
        _id: _id,
        type: type,
      });
    },
    changeVerify(_id, type) {
      this.clickChangeVerify({
        _id: _id,
        type: type,
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.setPageSize(val);
      this.findAllCar();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.setCurrent(val);
      this.findAllCar();
    },
    GpToUpDataCat(id) {
      this.$router.push({
        path: "upDataCat",
        query: {
          id,
        },
      });
    },
  },
  computed: {
    ...mapState(["carData"]),
  },
};
</script>

<style lang="scss" scoped>
.sector {
  width: 98%;
  box-shadow: 0px 2px 4px 0px #2233;
  background-color: #fff;
  margin: 0px auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
}
</style>
